package edu.uoc.tdp.pac4.connexiomanteniment.gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;

import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.UIManager;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


import edu.uoc.tdp.pac4.connexiomanteniment.*;
import edu.uoc.tdp.pac4.connexiomanteniment.i18n.*;
import edu.uoc.tdp.pac4.connexiomanteniment.exceptions.*;
import edu.uoc.tdp.pac4.server.connexiomanteniment.db.GestorUniversitats;
import edu.uoc.tdp.pac4.beans.Estudiante;
import java.util.Vector;
import java.util.Iterator;

import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JSeparator;


public class PantallaCercaUsuaris extends JFrame {

	private static final int SHORTLENGTH=16;
	private static final int MEDIUMLENGTH=32;
	private static final int LONGLENGTH=64;
	private static final int VERYLONGLENGTH=100;
	
	
	private static final long serialVersionUID = 3065279689452874985L;
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JComboBox comboBox;
	private JComboBox comboBox_1;	
	private JComboBox comboBox_2;
	private JLabel lblNewLabel_3; 	
    private JLabel lblProfile;
    private JLabel label_2;
    private JLabel label_3;
    private JLabel lblFirstName;
    private JLabel lblLastName;
    private JPanel panel;
    private JLabel label_1;
    private JButton button_1;
    private JButton button_2;
    private JButton button_3;
    private JLabel label;
    private JLabel label_4;
    private JLabel lblNewLabel;
    private JLabel lblNewLabel_1;
    private JLabel lblNewLabel_2;
    private JLabel lblNewLabel_4;
    private JLabel lblNewLabel_6;
    private JLabel lblNewLabel_7;
    private JLabel lblNewLabel_8;
    private JTable table;
    private DefaultTableModel dadesTaula;
    private JScrollPane scrollPane;
    private PantallaCercaUsuaris p; 
    private PantallaGestioUsuaris pRetorn;
    
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					PantallaCercaUsuaris frame = new PantallaCercaUsuaris(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PantallaCercaUsuaris(PantallaGestioUsuaris pR) {
		p = this;
		pRetorn = pR;
		setResizable(false);
		LanguageUtils.setDefaultLanguage("i18n/messagesConnexioManteniment");

		setTitle(LanguageUtils.getMessage("PantallaCercaUsuaris.usersSearchTitle.text"));
		setTitle(LanguageUtils.getMessage("PantallaCercaUsuaris.usersSearchTitle.text") + " - " + LanguageUtils.getMessage("PantallaCercaUsuaris.loggedAs.text") + ": " + Usuari.usuariConnectat.getNom() + " " + Usuari.usuariConnectat.getCognom1());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 596, 760);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		label_2 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.loginLabel.text"));
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setBounds(42, 122, 74, 19);
		contentPane.add(label_2);
		label_2.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		label_3 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.passwordLabel.text"));
		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
		label_3.setBounds(25, 150, 91, 20);
		contentPane.add(label_3);
		label_3.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		textField = new JTextField();
		textField.setBounds(127, 122, 278, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(127, 150, 278, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(127, 178, 278, 20);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		lblFirstName = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.firstnameLabel.text"));
		lblFirstName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblFirstName.setBounds(42, 180, 74, 19);
		contentPane.add(lblFirstName);
		lblFirstName.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		textField_3 = new JTextField();
		textField_3.setBounds(127, 204, 134, 20);
		contentPane.add(textField_3);
		textField_3.setColumns(10);
		
		lblLastName = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.lastnameLabel.text"));
		lblLastName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLastName.setBounds(13, 205, 103, 19);
		contentPane.add(lblLastName);
		lblLastName.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		fillRolesComboBox();
		comboBox.setBounds(127, 231, 278, 20);
		contentPane.add(comboBox);
		
		lblProfile = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.profileLabel.text"));
		lblProfile.setHorizontalAlignment(SwingConstants.RIGHT);
		lblProfile.setBounds(13, 231, 103, 20);
		contentPane.add(lblProfile);
		lblProfile.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
		
		panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 0, 596, 76);
		contentPane.add(panel);
		
		label_1 = new JLabel("");
		label_1.setIcon(new ImageIcon(PantallaCercaUsuaris.class.getResource("/images/logo.png")));
		label_1.setBounds(484, 6, 93, 55);
		panel.add(label_1);
		
		button_2 = new JButton(LanguageUtils.getMessage("PantallaCercaUsuaris.searchButton.text"));
		button_2.setIcon(new ImageIcon(PantallaCercaUsuaris.class.getResource("/images/user1_find.png")));
		button_2.setBounds(288, 21, 117, 29);
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				esborraLlista();
				GestorAcces ga = new GestorAcces();
				try { Vector<Usuari> v = ga.getLlistaUsuaris(recollirCriteriCerca());  mostraLlista(v); enableSelectButton(v.size() > 0);
				} catch (Exception e) { System.out.println(e.getLocalizedMessage()); e.printStackTrace(); }

			}
		});
		panel.add(button_2);
		
		button_1 = new JButton(LanguageUtils.getMessage("PantallaCercaUsuaris.newsearchButton.text"));
		button_1.setIcon(new ImageIcon(PantallaCercaUsuaris.class.getResource("/images/user1_add.png")));
		button_1.setBounds(170, 21, 117, 29);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) { netejarCriteriCerca(); esborraLlista(); enableSelectButton(false); }
		});
		panel.add(button_1);
		
		label = new JLabel("by SoftWebSolutions");
		label.setFont(new Font("Calibri", Font.PLAIN, 9));
		label.setBounds(38, 700, 84, 14);
		contentPane.add(label);
		
		label_4 = new JLabel("");
		label_4.setIcon(new ImageIcon(PantallaCercaUsuaris.class.getResource("/images/logo_empresa.png")));
		label_4.setBounds(6, 700, 27, 14);
		contentPane.add(label_4);
		
		lblNewLabel = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.idLabel.text"));
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(25, 94, 91, 16);
		contentPane.add(lblNewLabel);
		
		textField_4 = new JTextField();
		textField_4.setEditable(true);
		textField_4.setBounds(127, 88, 134, 28);
		contentPane.add(textField_4);
		textField_4.setColumns(10);
		textField_4.enableInputMethods(false);
		
		lblNewLabel_1 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.documentLabel.text"));
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(42, 261, 74, 16);
		contentPane.add(lblNewLabel_1);
		
		textField_5 = new JTextField();
		textField_5.setBounds(127, 255, 134, 28);
		contentPane.add(textField_5);
		textField_5.setColumns(10);
		
		lblNewLabel_2 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.documenttypeLabel.text"));
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(13, 290, 103, 16);
		contentPane.add(lblNewLabel_2);
		
		// comboBox_1 = new JComboBox();
		fillDocTypesComboBox();
		comboBox_1.setBounds(127, 285, 134, 27);
		contentPane.add(comboBox_1);
		
		lblNewLabel_3 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.universityLabel.text"));
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_3.setBounds(42, 346, 74, 16);
		contentPane.add(lblNewLabel_3);
		
		comboBox_2 = new JComboBox();
		comboBox_2.setEditable(false);
		comboBox_2.setEnabled(true);
		comboBox_2.setBounds(127, 340, 278, 27);
		contentPane.add(comboBox_2);
		fillUniversitiesComboBox();
		
		lblNewLabel_4 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.emailLabel.text"));
		lblNewLabel_4.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_4.setBounds(42, 318, 74, 16);
		contentPane.add(lblNewLabel_4);
		
		textField_6 = new JTextField();
		textField_6.setBounds(127, 313, 278, 28);
		contentPane.add(textField_6);
		textField_6.setColumns(10);
		
		lblNewLabel_6 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.creationDateLabel.text"));
		lblNewLabel_6.setBounds(434, 157, 103, 16);
		contentPane.add(lblNewLabel_6);
		
		textField_7 = new JTextField();
		textField_7.setBounds(429, 174, 134, 28);
		contentPane.add(textField_7);
		textField_7.setColumns(10);
		
		lblNewLabel_7 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.modificationDateLabel.text"));
		lblNewLabel_7.setBounds(434, 209, 129, 16);
		contentPane.add(lblNewLabel_7);
		
		textField_8 = new JTextField();
		textField_8.setBounds(429, 226, 134, 28);
		contentPane.add(textField_8);
		textField_8.setColumns(10);
		
		lblNewLabel_8 = new JLabel(LanguageUtils.getMessage("PantallaCercaUsuaris.deletionDateLabel.text"));
		lblNewLabel_8.setBounds(434, 261, 103, 16);
		contentPane.add(lblNewLabel_8);
		
		textField_9 = new JTextField();
		textField_9.setBounds(429, 278, 134, 28);
		contentPane.add(textField_9);
		textField_9.setColumns(10);

		textField_10 = new JTextField();
		textField_10.setBounds(263, 204, 134, 20);
		contentPane.add(textField_10);
		
		dadesTaula = new DefaultTableModel();
	    table = new JTable(dadesTaula);
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.idLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.loginLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.documenttypeLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.documentLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.firstnameLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.firstfamilynameLabel.text"));
	    dadesTaula.addColumn(LanguageUtils.getMessage("PantallaCercaUsuaris.secondfamilynameLabel.text"));
		
		scrollPane = new JScrollPane(table);
		scrollPane.setBounds(25, 394, 539, 256);
		contentPane.add(scrollPane);		
		
		button_3 = new JButton(LanguageUtils.getMessage("PantallaCercaUsuaris.selectButton.text"));
		button_3.setBounds(234, 662, 117, 29);
		contentPane.add(button_3);
		button_3.setIcon(new ImageIcon(PantallaCercaUsuaris.class.getResource("/images/user1_preferences.png")));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				boolean ok = true;
				if (p.table.getSelectedRowCount() == 0) try { ok = false; throw new ExceptionConsultaUsuari("PantallaError.errorSel.leccio.capusuarisel.lecionat"); } catch (Exception e) {} 
				if (p.table.getSelectedRowCount() > 1) try { ok = false; throw new ExceptionConsultaUsuari("PantallaError.errorSel.leccio.massausuarissel.lecionats"); } catch (Exception e) {}
				if (ok) { pRetorn.loadUsuari((String)dadesTaula.getValueAt(p.table.getSelectedRow(), 1)); p.setVisible(false); }
			}
		});
		
		JSeparator separator = new JSeparator();
		separator.setBounds(13, 375, 568, 12);
		contentPane.add(separator);
		
		JButton button_4 = new JButton(LanguageUtils.getMessage("PantallaCercaUsuaris.closeButton.text"));
		button_4.setBounds(383, 662, 180, 29);
		button_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { p.setVisible(false); }});
		contentPane.add(button_4);
		
		enableSelectButton(false);
	}
	
	private void fillRolesComboBox() {
		String[] elsRols = new String[4];
		elsRols[0] = "";
		elsRols[1] = LanguageUtils.getMessage("PantallaCercaUsuaris.roleEstudiant.text");
		elsRols[2] = LanguageUtils.getMessage("PantallaCercaUsuaris.roleAdministrador.text");
		elsRols[3] = LanguageUtils.getMessage("PantallaCercaUsuaris.roleResponsableEvents.text");
		comboBox = new JComboBox(elsRols);
	}

	private void fillDocTypesComboBox() {
		String[] elsTipusDocument = new String[5];
		elsTipusDocument[0] = "";
		elsTipusDocument[1] = LanguageUtils.getMessage("PantallaCercaUsuaris.docTypeNIF.text");
		elsTipusDocument[2] = LanguageUtils.getMessage("PantallaCercaUsuaris.docTypeNIE.text");
		elsTipusDocument[3] = LanguageUtils.getMessage("PantallaCercaUsuaris.docTypePassaport.text");
		elsTipusDocument[4] = LanguageUtils.getMessage("PantallaCercaUsuaris.docTypeAltres.text");
		comboBox_1 = new JComboBox(elsTipusDocument);		
	}
	
	private void fillUniversitiesComboBox() {
		GestorUniversitats guni = new GestorUniversitats();
		Vector<String> v = null;
		try { v = guni.getUniversitats(); } catch (Exception e) { }
		String[] universityNames = new String[v.size() + 1];
		universityNames[0] = "";
		Iterator<String> it = v.iterator();
		comboBox_2.removeAllItems(); comboBox_2.addItem("");
		while (it.hasNext()) { comboBox_2.addItem(it.next()); }
	}
	
	public Integer getIdIntern() { String s = textField_4.getText(); return (s == null || "".equals(s.trim())? null : new Integer(s.trim()));  }
	public void setIdIntern(Integer pIdIntern) { String s = (pIdIntern == null? "" : pIdIntern.toString()); textField_4.setText(s); }
	public String getIdUsuari() { return (textField.getText() == null ? null : textField.getText().trim()); } 
	public void setIdUsuari(String pIdUsuari) { textField.setText(pIdUsuari == null ? "" : pIdUsuari);}
	public String getPwd() { return (textField_1.getText() == null ? null : textField_1.getText().trim()); }
	public void setPwd(String pPwd) { textField_1.setText(pPwd == null ? "" : pPwd); }
	public String getNom() { return (textField_2.getText() == null ? null : textField_2.getText().trim()); }
	public void setNom(String pNom) { textField_2.setText(pNom == null ? "" : pNom); }
	public String getCognom1() { return (textField_3.getText() == null ? null : textField_3.getText().trim()); }
	public void setCognom1(String pCognom1) { textField_3.setText(pCognom1 == null ? "" : pCognom1); }
	public String getCognom2() { return (textField_10.getText() == null ? null : textField_10.getText().trim()); }
	public void setCognom2(String pCognom2) { textField_10.setText(pCognom2 == null ? "" : pCognom2); }
	public String getMail() { return (textField_6.getText() == null ? null : textField_6.getText().trim()); }
	public void setMail(String pEmail) { textField_6.setText(pEmail == null ? "" : pEmail); }
	public String getDocument() { return (textField_5.getText() == null ? null : textField_5.getText().trim()); }
	public void setDocument(String pDocument) { textField_5.setText(pDocument == null ? "" : pDocument); }
    public String getTipusDocument() { 
		String value = (String)comboBox_1.getSelectedItem();
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeNIF.text"))) return "NIF";
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeNIE.text"))) return "NIE";
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypePassaport.text"))) return "PAS";
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeAltres.text"))) return "ALT";
		// mai hauriem d'arribar aqui
//		try { throw new ExceptionMantenimentUsuari("PantallaError.ErrorMantenimentUsuaris.unexpectedDocTypeValue.text"); } catch (Exception e) {} 
		return "";
    }
    public void setTipusDocument(String pTipusDocument) {
    	if (pTipusDocument == null) try { throw new ExceptionMantenimentUsuari("PantallaError.ErrorMantenimentUsuaris.unexpectedDocTypeValue.text"); } catch (Exception e) {} 
        if (pTipusDocument.equals("NIF")) { comboBox_1.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeNIF.text")); return; }
        if (pTipusDocument.equals("NIE")) { comboBox_1.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeNIE.text")); return; }
        if (pTipusDocument.equals("PAS")) { comboBox_1.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypePassaport.text")); return; }
        if (pTipusDocument.equals("ALT")) { comboBox_1.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.docTypeAltres.text")); return; }
        if (pTipusDocument.equals("")) { comboBox_1.setSelectedItem(""); return; }
		// mai hauriem d'arribar aqui
//		try { throw new ExceptionMantenimentUsuari("PantallaError.ErrorMantenimentUsuaris.unexpectedDocTypeValue.text"); } catch (Exception e) {} 			
    }
	public Date getDataCreacio() { String s = textField_7.getText(); return ((s == null || "".equals(s.trim())? null : new Date(s.trim()))); } // ESTIC AQUI 
    public void setDataCreacio(Date pDataCreacio) {
    	if (pDataCreacio == null) {
        	textField_7.setText(null);
        	return;
    	}
        DateFormat dateFormatter;
        dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault());
        textField_7.setText(dateFormatter.format(pDataCreacio));    
    }
//	public Date getDataModificacio() { return dataModificacio; } 
	public void setDataModificacio(Date pDataModificacio) { textField_8.setText(pDataModificacio == null ? "" : pDataModificacio.toString()); } 
//	public Date getDataEsborrat() { return dataEsborrat; } 
	public void setDataEsborrat(Date pDataEsborrat) { textField_8.setText(pDataEsborrat == null ? "" : pDataEsborrat.toString()); } 
//	public Administrador getUsuariCreacio() { return usuariCreacio; } 
//	public void setUsuariCreacio(Administrador pUsuariCreacio) { usuariCreacio = pUsuariCreacio; } 
//	public Administrador getUsuariModificacio() { return usuariModificacio; } 
//	public void setUsuariModificacio(Administrador pUsuariModificacio) { usuariModificacio = pUsuariModificacio; } 
//	public Administrador getUsuariEsborrat() { return usuariEsborrat; } 
//	public void setUsuariEsborrat(Administrador pUsuariEsborrat) { usuariEsborrat = pUsuariEsborrat; }
	public char getTipusUsuari() {
		String value = (String)comboBox.getSelectedItem();
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.roleEstudiant.text"))) return 'E';
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.roleAdministrador.text"))) return 'A';
		if (value.equals(LanguageUtils.getMessage("PantallaGestioUsuaris.roleResponsableEvents.text"))) return 'R';
		// mai hauriem d'arribar aqui
//		try { throw new ExceptionMantenimentUsuari("PantallaError.ErrorMantenimentUsuaris.unexpectedRoleValue.text"); } catch (Exception e) {} 
		return 'c';
	}
	public void setTipusUsuari(char pTipusUsuari) {
		switch (pTipusUsuari) {
		case 'A' : comboBox.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.roleAdministrador.text")); break;  
		case 'E' : comboBox.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.roleEstudiant.text")); break;  
		case 'R' : comboBox.setSelectedItem(LanguageUtils.getMessage("PantallaGestioUsuaris.roleResponsableEvents.text")); break;
		case ' ' : comboBox.setSelectedItem(LanguageUtils.getMessage("")); break; 
		default:  // mai hauriem d'arribar aqui
//			try { throw new ExceptionMantenimentUsuari("PantallaError.ErrorMantenimentUsuaris.unexpectedRoleValue.text"); } catch (Exception e) {} 			
		}
	}
	public String getUniversitat() { return (String)comboBox_2.getSelectedItem() == null ? null : ((String)comboBox_2.getSelectedItem()).trim(); }
	public void setUniveritat(String pUniversitat) { comboBox_2.setSelectedItem(pUniversitat); }
		
	private Estudiante recollirCriteriCerca() {
		Estudiante u = new Estudiante();
		setDataCreacio(u.getDataCreacio()); setDataModificacio(u.getDataModificacio()); setDataEsborrat(u.getDataEsborrat());

	    u.setIdIntern(getIdIntern()); u.setIdUsuari(getIdUsuari()); u.setPwd(getPwd()); u.setNom(getNom()); u.setCognom1(getCognom1()); u.setCognom2(getCognom2());
	    u.setMail(getMail()); u.setDocument(getDocument()); u.setTipusDocumentId(getTipusDocument());
	    u.setTipusUsuari(getTipusUsuari()); 
	    u.setDataCreacio(getDataCreacio());
	    u.setUniversitat(getUniversitat());
	    // FALTEN DATES I USUARI ADMIN QUE HA FEL ELS CANVIS AL CRITERI DE CERCA que no estan en Usuari 
	    return u;
	}
	
	private void mostraLlista( Vector<Usuari> v) {
		int i;
		for(i=0;i<v.size();i++) {
			Usuari u = v.elementAt(i);
			Vector<Object> fila = new Vector<Object>();
			fila.add(u.getIdIntern()); fila.add(u.getIdUsuari()); fila.add(u.getTipusDocumentId()); fila.add(u.getDocument()); fila.add(u.getNom()); fila.add(u.getCognom1()); fila.add(u.getCognom2());
			dadesTaula.addRow(fila);
		}
	}
	
	private void esborraLlista() {
		while (dadesTaula.getRowCount() > 0) dadesTaula.removeRow(0); 
	}
	
	private void netejarCriteriCerca() {
		setIdIntern(null); setIdUsuari(""); setPwd(""); setMail(""); setNom(""); setCognom1(""); setCognom2("");
		setTipusUsuari(' '); setTipusDocument(""); setDocument(""); 
		setDataCreacio(null); setDataModificacio(null); setDataEsborrat(null); 
		fillUniversitiesComboBox();		
	}
	
	private void enableSelectButton(boolean b) {
		button_3.setEnabled(b);
	}
} 
